package stat;

import java.io.*;
import java.util.*;

public class LogReader {	
	public static Map<String, ArrayList<LogReaderLine>> getMap(String file) {
		Map<String, ArrayList<LogReaderLine>> map = new HashMap<String, ArrayList<LogReaderLine>>();
		
		try {
			BufferedReader br = new BufferedReader(new FileReader(file));
			String str;
			while ((str = br.readLine()) != null){
				String[] array = str.split(";");
				
				long downloadTime = new Long(array[0]);
				String currentPeer = array[1];
				int piece = new Integer(array[2]);
				float percentageDone = new Float(array[3].substring(0, array[3].length()-3));
				
				if(!map.containsKey(currentPeer)){
					ArrayList<LogReaderLine> list = new ArrayList<LogReaderLine>();
					map.put(currentPeer, list);
				}
				map.get(currentPeer).add(new LogReaderLine(downloadTime, currentPeer, piece, percentageDone));
			}
		} catch(IOException e) {
			return null;
		} 
		
		return map;
	}
}